package com.jarveis.dbs.core.init;

import java.io.IOException;

import org.apache.log4j.Logger;

import com.jarveis.dbs.core.DBService;
import com.jarveis.dbs.core.DBServiceImpl;
import com.jarveis.frame.lang.StringUtil;
import com.jarveis.frame.util.Param;

/**
 * 数据访问入口
 * 
 * @author liuguojun
 * @date 2017-08-08
 */
public class DBS4Application {

	private static Logger logger = Logger.getLogger(DBS4Application.class);

	private volatile static DBS4Application instance = null;

	/**
	 * 获取实例
	 */
	public static DBS4Application getInstance() {
		if (instance == null) {
			synchronized (DBS4Application.class) {
				if (instance == null) {
					instance = new DBS4Application();
				}
			}
		}
		return instance;

	}

	public String process(String message) {
		try {
			if (!StringUtil.isEmpty(message)) {
				DBService dbservice = new DBServiceImpl();
				message = dbservice.process(message);
				return message;
			} else {
				return null;
			}
		} catch (Exception ex) {
			logger.error(ex.getMessage(), ex);
			return null;
		}
	}
	
	public static void main(String[] args) throws Exception{
		Param in = new Param(Param.REQ);
    	in.getHead().setProperty("@device", StringUtil.getUUID());
    	in.getHead().setProperty("@funcId", "10001");
    	in.getHead().setProperty("@dataType", "json");
    	in.getBody().setProperty("@name", "Tom");
    	String message = in.toJsonString();
    	
		message = DBS4Application.getInstance().process(message);
		logger.info(message);
	}

}
